import pygame, math
from Arrow import Arrow
from Creature import Creature

class Player(Creature):
	def __init__(self, pos):
		Creature.__init__(self, "RSC/Hat.png", [0,0], pos, 9, 9)
		self.image = pygame.image.load("RSC/Hat.png")
		self.facing = "up"
		self.changed = False
		self.frame = 0
		#self.maxFrame = len(self.images) - 1
		self.waitCount = 0
		self.maxWait = 60*.25
		#self.image = self.images[self.frame]
		self.rect = self.image.get_rect(center = self.rect.center)
		self.maxSpeed = 30
		self.shooting = False
		self.moving = False
		self.maxHurtDelay = 60 * 2
		self.hurtDelay = 0
		self.invincible = False
		self.living = True
		self.maxAmmo = 999
		
	
	def shoot(self, command = ""):
		if command == "stop":
			self.shooting = False
		#if self.gun.coolDown == 0:
			#self.gun.coolDown += 1
		return [Bullet(self.rect.center, self.facing, 10)]
		
			
	def update(self, screenWidth, height):
		Creature.update(self, screenWidth, height)
		#self.animate()
		#self.changed = False
		#if self.hurtDelay > 0:
			#self.hurtDelay -= 1
		#else:
			#self.invincible = False
		
	def collideWall(self, screenWidth, height):
		if self.rect.left < 0 or self.rect.right > width:
			self.speedx = -self.speedx
			self.update(screenWidth, height)
			self.speedx = 0
		if self.rect.top < 0 or self.rect.bottom > height:
			self.speedy = -self.speedy
			self.update(screenWidth, height)
			self.speedy = 0
				
	
	#def animate(self):
		#if self.moving:
			#if self.waitCount < self.maxWait:
				#self.waitCount += 1
			#else:
				#self.waitCount = 0
				#self.changed = True
				#if self.frame < self.maxFrame:
					#self.frame += 1
				#else:
					#self.frame = 0
					#if self.shooting:
						#self.shooting = False
						#self.images = self.upImages
					#if self.stabbing:
						#self.stabbing = False
						#self.images = self.upImages
		#else:
			#self.waitCount = self.maxWait
		
		#if self.changed:    
			#if self.facing == "up":
				#if self.shooting:
					#self.images = self.upRangedImages
				#elif self.stabbing:
					#self.images = self.upKnifeImages
				#else:
					#self.images = self.upImages
			#elif self.facing == "down":
				#self.images = self.downImages
			#elif self.facing == "right":
				#self.images = self.rightImages
			#elif self.facing == "left":
				#self.images = self.leftImages
			
			#self.image = self.images[self.frame]
	
	def collideMonster(self, other):
		if self.rect.right > other.rect.left and self.rect.left < other.rect.right:
			if self.rect.bottom > other.rect.top and self.rect.top < other.rect.bottom:
				if (self.radius + other.radius) > self.distance(other.rect.center):
					self.hurt()
	
		
	def hurt(self, amount=1):
		if not self.invincible:
			self.health -= amount
			self.invincible = True
			self.hurtDelay = self.maxHurtDelay
		
		if self.health <=0:
			self.living = False
			
	def go(self, direction):
		if direction == "up":
			self.facing = "up"
			self.changed = True
			self.speedy = -self.maxSpeed
			self.moving = True
		elif direction == "stop up":
			self.speedy = 0
			self.changed = True
			self.moving = False
		elif direction == "down":
			self.facing = "down"
			self.changed = True
			self.speedy = self.maxSpeed
			self.moving = True
		elif direction == "stop down":
			self.speedy = 0
			self.moving = False
			
		if direction == "right":
			self.facing = "right"
			self.changed = True
			self.speedx = self.maxSpeed
			self.moving = True
		elif direction == "stop right":
			self.speedx = 0
			self.moving = False
		elif direction == "left":
			self.facing = "left"
			self.changed = True
			self.speedx = -self.maxSpeed
			self.moving = True
		elif direction == "stop left":
			self.speedx = 0
			self.moving = False
		elif direction == "stop":
			print self.rect
			self.speedx = 0
			self.speedy = 0
			self.moving = False
			
